#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e5 + 5;

int n, m;
int ans[N], deg[N];
vector<int> hunter[N];
vector<int> food[N];
int st[N][18], dep[N];

int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  int d = dep[u] - dep[v];
  per(i, 16, 0) if (d & (1 << i)) u = st[u][i];
  if (u == v) return u;
  per(i, 16, 0) if (st[u][i] != st[v][i]) u = st[u][i], v = st[v][i];
  return st[u][0];
}

void add(int u) {
  if (!u || food[u].empty()) return;
  int x = food[u][0];
  for (int y : food[u]) {
    x = lca(x, y);
  }
  dep[u] = dep[x] + 1;
  st[u][0] = x;
  rep(i, 1, 16) st[u][i] = st[st[u][i - 1]][i - 1];
}
void toposort() {
  vector<int> seq;
  queue<int> q;
  q.push(0);
  while (q.size()) {
    int u = q.front();
    q.pop();
    seq.push_back(u);
    for (int v : hunter[u]) {
      if (--deg[v] == 0) {
        q.push(v);
        add(v);
      }
    }
  }
  reverse(seq.begin(), seq.end());
  for (int v : seq) {
    int u = st[v][0];
    ans[u] += ans[v] + 1;
  }
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  rep(i, 1, n) {
    int x;
    while ((cin >> x) && x) {
      hunter[x].push_back(i);
      deg[i]++;
      food[i].push_back(x);
    }
    if (!deg[i]) {
      hunter[0].push_back(i);
      deg[i]++;
      food[i].push_back(0);
    }
  }
  toposort();
  rep(i, 1, n) cout << ans[i] << endl;
  return 0;
}